import request from "@/utils/request";

// 分页展示数据类型  // spu信息数据类型
export interface PagingItemType {
  id?: number;
  spuName: string;
  description: string;
  category3Id: number;
  tmId: number | null;
  spuSaleAttrList: null | addSalesAttrListType;
  spuImageList: null | spuImageListType;
}
// 销售属性值类型
export interface salseAttrValueItemType {
  baseSaleAttrId: number;
  saleAttrName: string;
  saleAttrValueName: string;
}
// 销售属性值列表类型
export type salseAttrValueListType = salseAttrValueItemType[];

// 销售属性类性
export interface salseAttrItemType {
  id?: number;
  spuId?: number;
  baseSaleAttrId: number;
  saleAttrName: string;
  spuSaleAttrValueList: salseAttrValueListType;
  isEdit?: boolean;
}
// 添加销售属性列表类型
export type addSalesAttrListType = salseAttrItemType[];

// 图片数据类型
export interface spuImageItemType {
  id?: number;
  spuId?: number;
  imgName: string;
  imgUrl: string;
}
// 图片列表数据类型
export type spuImageListType = spuImageItemType[];

// 分页列表类型
export type PagingListType = PagingItemType[];

// 请求分页列表返回值类型
export interface reqGetPagingListType {
  records: PagingListType;
  total: number;
  size: number;
  current: number;
  searchCount: boolean;
  pages: number;
}

// 获取分页列表数据
export const reqGetPagingList = (
  page: number,
  limit: number,
  category3Id: number
) => {
  return request.get<null, reqGetPagingListType>(
    `/admin/product/${page}/${limit}?category3Id=${category3Id}`
  );
};

// 销售属性数据类型
export interface salesAttrItemType {
  id: number;
  name: string;
}

// 销售属性列表数据类型
export type salesAttrListType = salesAttrItemType[];

// 请求所有的销售属性列表
export const reqGetAllSalesAttrList = () => {
  return request.get<null, salesAttrListType>(
    `/admin/product/baseSaleAttrList`
  );
};

// 请求新增spu
export const reqAddSpuInfo = (spuInfo: PagingItemType) => {
  return request.post(`/admin/product/saveSpuInfo`, spuInfo);
};

// 请求修改spu
export const reqUpdataSpuInfo = (spuInfo: PagingItemType) => {
  return request.post(`/admin/product/updateSpuInfo`, spuInfo);
};

// 根据spuId 获取自己销售属性列表
export const reqGetSalesAttrListBySpuId = (spuId: number) => {
  return request.get<null, addSalesAttrListType>(
    `/admin/product/spuSaleAttrList/${spuId}`
  );
};

// 根据spuId 获取自己的图片列表
export const reqGetImageListBySpuId = (spuId: number) => {
  return request.get<null, spuImageListType>(
    `/admin/product/spuImageList/${spuId}`
  );
};
